home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-07 / lanbook.zip / NOSIF.ASM < prev    next >
Assembly Source File  |  1991-09-22  |  6KB  |  220 lines

  1. ;
  2. ;   NOSIF.ASM
  3. ;
  4. ;   (c) 1991   Adrian J.King
  5. ;
  6. ;        This code was developed for inclusion in the book
  7. ;        "Running LANtastic", by Adrian King, published by
  8. ;        Bantam Books, October 1991.
  9. ;
  10. ;   This module includes the C to assembler interface routines needed
  11. ;   to interface correctly between the NOS and the LANRES program.
  12. ;
  13. ; $Header:   C:/USR/LANBOOK/SRC2/LAN/VCS/NOSIF.ASV   1.1   22 Sep 1991  8:22:40  $
  14. ;
  15. ; $Log:   C:/USR/LANBOOK/SRC2/LAN/VCS/NOSIF.ASV  $
  16. ;
  17. ;   Rev 1.1   22 Sep 1991  8:22:40
  18. ;Moved entercrit() and leavecrit() into this module.
  19. ;Cosmetic touch ups.
  20. ;
  21. ;   Rev 1.0   13 Jul 1991 11:20:24
  22. ;Initial revision.
  23. ;
  24.  
  25.     .model  small,C
  26.  
  27.     .data
  28.  
  29.     EXTRN   oldservice:FAR      ; Address of old msg service vector
  30.     EXTRN    olddos:FAR            ; Address of old DOS vector
  31.         
  32.     PUBLIC  bworktodo            
  33.  
  34. bworktodo   dw  0                ; Non-zero when there is work to do
  35. bcalled        dw    0                ; Non-zero when dowork() already called
  36.  
  37.     .code
  38.  
  39.     PUBLIC  msg_interrupt       ; Entered from LANOS when msg received
  40.     PUBLIC  nos_interrupt        ; Called by LANOS when DOS can be called
  41.  
  42.     PUBLIC  nowhere             ; Null routine used as target for
  43.                                 ; call to old message service until
  44.                                 ; the proper target has been setup
  45.  
  46.     PUBLIC    entercrit            ; Enter a critical region
  47.     PUBLIC    leavecrit            ; Leave a critical region
  48.  
  49.     EXTRN    msg_proc:FAR        ; New message service processor
  50.     EXTRN    dowork:FAR            ; NOS idle time processor
  51.  
  52. msg_interrupt   PROC    FAR
  53.  
  54.     ; This routine is used as the target for the SET MESSAGE SERVICE
  55.     ; call to NOS. It calls the msg_proc routine in the lanres.c module. 
  56.     ;
  57.     ; Entry:        ES:BX points to message
  58.     ;               All other registers unknown but will be saved
  59.     ;
  60.     ; Processing:   Call the old message service vector (retrieved by the
  61.     ;               GET MESSAGE SERVICE call to NOS).
  62.     ;       
  63.     ;               Call the msg_proc routine with the message pointer
  64.     ;
  65.     ; Exit:         All registers restored to their values on entry.
  66.     ;
  67.  
  68.     assume    ds:NOTHING
  69.  
  70.     cli
  71.     push    ax
  72.     push    ds
  73.     mov     ax,DGROUP                ; Set up C runtime DS
  74.     mov     ds,ax
  75.     assume  ds:DGROUP        
  76.  
  77.                                     ; Save everything except flags, which       
  78.                                     ; will be restored via IRET
  79.     push    si
  80.     push    di
  81.     push    bp
  82.     push    cx
  83.     push    dx
  84.     push    es                          ; ES:BX will be parameter to msg_proc()
  85.     push    bx
  86.  
  87.     push    ds                        ; Save DS through next call
  88.     pushf                           ; Old service returns via IRET,
  89.                                     ; so simulate an INT by pushing flags
  90.                                     ; and making a far call. 
  91.  
  92.     call    dword ptr oldservice    ; Call old message service
  93.     pop        ds
  94.     call    msg_proc                ; Call our message service
  95.  
  96.     pop     bx                      ; Restore everything
  97.     pop     es
  98.     pop     dx
  99.     pop     cx
  100.     pop     bp
  101.     pop     di
  102.     pop     si
  103.     pop        ds
  104.     pop     ax
  105.     sti
  106.     iret                            ; We were called via an INT, so we IRET
  107.  
  108. msg_interrupt   ENDP
  109.  
  110. nos_interrupt   PROC    FAR
  111.  
  112.     ; This routine is used as the target for the DOS SERVICE VECTOR
  113.     ; call to NOS. It calls the dowork() routine in the lanlib.c module. 
  114.     ;
  115.     ; Entry:        All registers unknown but will be saved
  116.     ;
  117.     ; Processing:   Call the old DOS service vector (retrieved by the
  118.     ;               GET SERVICE VECTOR call to NOS).
  119.     ;       
  120.     ;               Call the dowork() routine.
  121.     ;
  122.     ; Exit:         All registers restored to their values on entry.
  123.     ;
  124.  
  125.     assume  ds:NOTHING
  126.  
  127.     cli
  128.     push    ax                        ; Save AX
  129.     push    ds
  130.     mov     ax,DGROUP                ; Set up C runtime DS
  131.     mov     ds,ax
  132.  
  133.     assume  ds:DGROUP
  134.  
  135. dos_main:
  136.     mov        ax,bcalled                ; Check re-entrancy
  137.     jnz        no_call                    ; Already running, leave
  138.     mov        ax,bworktodo            ; Only call when there is work to do
  139.     or        ax,ax
  140.     jnz        dos_call                ; Yes, go process work request
  141.  
  142. no_call:
  143.     pop        ds                        ; No work. Leave.
  144.     pop        ax                        
  145.     sti
  146.     iret
  147.  
  148. dos_call:
  149.     mov        bcalled,ax                ; Set lock so dowork() only gets
  150.                                     ; called once
  151.     sti
  152.  
  153.                                     ; Save everything except flags, which       
  154.                                     ; will be restored via IRET
  155.     push    si
  156.     push    di
  157.     push    bp
  158.     push    cx
  159.     push    dx
  160.     push    es
  161.     push    bx
  162.  
  163.     push    ds                        ; Save DS through next call
  164.     pushf                           ; Old service returns via IRET,
  165.                                     ; so simulate an INT by pushing flags
  166.                                     ; and making a far call. 
  167.  
  168.     call    dword ptr olddos        ; Call old DOS service
  169.     pop        ds    
  170.     call    dowork                    ; Call our DOS service routine
  171.  
  172.     pop     bx                      ; Restore everything
  173.     pop     es
  174.     pop     dx
  175.     pop     cx
  176.     pop     bp
  177.     pop     di
  178.     pop     si
  179.     cli                                ; Clear called flag carefully
  180.     xor        ax,ax    
  181.     mov        bcalled,ax
  182.     pop        ds
  183.     pop     ax
  184.     sti
  185.     iret                            ; We were called via an INT, so we IRET
  186.  
  187. nos_interrupt   ENDP
  188.  
  189. nowhere PROC    FAR
  190.  
  191.     ; This routine does nothing. It is used as a target for the call to
  192.     ; the old message service in case the old message service address is
  193.     ; not properly setup. (I.e. it avoids a jump into hyperspace.)
  194.     ; This could be a C interrupt procedure with a null body.
  195.     
  196.     iret                            ; Just return, as if from an INT
  197.  
  198. nowhere ENDP
  199.  
  200. ;
  201. ;    Enter and leave a critical region. Called by LANRES when fiddling
  202. ;    with global data structures.
  203. ;
  204.  
  205. entercrit PROC    FAR
  206.  
  207.     cli
  208.     ret
  209.  
  210. entercrit ENDP
  211.  
  212. leavecrit PROC    FAR
  213.  
  214.     sti
  215.     ret
  216.  
  217. leavecrit ENDP
  218.  
  219.     END
  220.